package com.gxcc3.ygps.web.controller.video;


import com.gxcc3.ygps.common.annotation.Log;
import com.gxcc3.ygps.common.core.controller.BaseController;
import com.gxcc3.ygps.common.core.domain.AjaxResult;
import com.gxcc3.ygps.common.core.domain.entity.SysIotCar;
import com.gxcc3.ygps.common.core.domain.entity.SysIotStorage;
import com.gxcc3.ygps.common.core.domain.entity.SysVideoMonitor;
import com.gxcc3.ygps.common.core.page.TableDataInfo;
import com.gxcc3.ygps.common.enums.BusinessType;
import com.gxcc3.ygps.common.utils.uuid.IdUtils;
import com.gxcc3.ygps.system.service.ISysVideoMonitorService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 视频监控 监控设备
 */
@RestController
@RequestMapping("/video/monitor")
public class SysVideoMonitorController extends BaseController {


    @Resource
    ISysVideoMonitorService monitorService;


    /**
     * 车辆列表
     */
    @PreAuthorize("@ss.hasPermi('video:monitor:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysVideoMonitor monitor)
    {
        startPage();
        monitor.setCompanyId(getCompanyId());
        List<SysIotStorage> list = monitorService.selectMonitorList(monitor);
        return getDataTable(list);
    }


    /**
     * 新增监控
     */
    @Log(title = "监控管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @PreAuthorize("@ss.hasPermi('video:monitor:add')")
    public AjaxResult add(@Validated @RequestBody SysVideoMonitor monitor){
        monitor.setCreateBy(getUsername());
        monitor.setCompanyId(getCompanyId());
        monitor.setReportStatus("1");
        monitor.setReportDeviceNo(IdUtils.randomSnowId());
        return toAjax(monitorService.insertMonitor(monitor));
    }


    /**
     * 获取监控信息
     */
    @GetMapping("/{id}")
    @PreAuthorize("@ss.hasPermi('video:monitor:query')")
    public AjaxResult getMonitor(@PathVariable Long id){
        return success(monitorService.selectMonitorById(id));
    }


    /**
     * 修改车辆信息
     */
    @PostMapping("/edit")
    @PreAuthorize("@ss.hasPermi('video:monitor:edit')")
    public AjaxResult edit(@Validated @RequestBody SysVideoMonitor monitor){
        monitor.setCreateBy(getUsername());
        return toAjax(monitorService.updateMonitor(monitor));
    }


    /**
     * 删除监控
     */
    @PostMapping("/remove/{ids}")
    @PreAuthorize("@ss.hasPermi('video:monitor:remove')")
    public AjaxResult delMonitor(@PathVariable Long[] ids){
        return toAjax(monitorService.delMonitor(ids));
    }
}
